<?php

namespace Maka\Tool\Idownload;

class Aes
{
    static private  $config = [
        'key' => 'd4ede173f99afaa24ea33b37aaec9d71',
        'iv' => 'bbbbbbbbiibbbbbi'
    ];
   
    /**
     *  加密
     * @param  string   $content  [需要加密的字符串]
     * @return string   [加密后的密文]
     * @date: 2020-10-23 08:54:34
    */
    public static function encrypt ($content) {
        return openssl_encrypt($content, 'AES-128-CBC', self::$config['key'], 0, self::$config['iv']);
    }

    /**
     * 解密
     * @param  string   $ciphertext   [密文]
     * @return string   [解密后的原文]
     * @date: 2020-10-23 08:56:25
    */
    public static function decrypt ($ciphertext, $key=false, $iv=false) {
        $key = $key ?: self::$config['key'];
        $iv = $iv ?: self::$config['iv'];
        return openssl_decrypt($ciphertext, 'AES-128-CBC', $key, 0, $iv);
    }
}

